package com.dy.hander;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


/**
 * @ClassName:
 * @Author: 仄言in
 * @Desctiption: (描述) 拦截登录的条件
 * @Date: 2021/7/25 17:09
 * @Version 1.0 (版本)
 */
@Component
public class LoginHander implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){
        if (request.getSession().getAttribute("user") == null) {
            try {
                response.sendRedirect("/login");
            } catch (IOException e) {
                //e.printStackTrace();
            }
            return false;
        }
        return true;
    }
}
